import request from '@/utils/request.js';

export const registerService = (registerData) => {
    var params = new URLSearchParams()
    for (let key in registerData) {
        params.append(key, registerData[key])
    }
    return request.post('/user/register', params)
}

export const loginService = (loginData) => {
    var params = new URLSearchParams()
    for (let key in loginData) {
        params.append(key, loginData[key])
    }
    return request.post('/user/login', params)
}

//获取个人信息
export const userInfoService = ()=>{
    return request.get('/user/userInfo');
}



//获取个人信息
export const userInfoUpdateService = (userInfoData)=>{
    // var params = new URLSearchParams()
    // for (let key in userInfoData) {
    //     params.append(key, userInfoData[key])
    // }
    return request.put('/user/update',userInfoData);
}

export const userAvatarUpdateService = (avatarUrl)=>{
    const params = new URLSearchParams()
    params.append('avatarUrl',avatarUrl)
    return request.patch('/user/updateAvatar',params);
}



// export const userPwdUpdateService = (resetPwdData)=>{
//     var params = new URLSearchParams()
//     for (let key in resetPwdData) {
//         params.append(key, resetPwdData[key])
//     }
    
//     // console.log(resetPwdData)
//     console.log(params)
//     // console.log(token)
//     return request.patch('/user/updatePwd',params);
// }

export const userPwdUpdateService = async (resetPwdData,token) => {  
    // 直接发送JSON数据  
    return request.patch('/user/updatePwd', resetPwdData, {  
        headers: {  
            'Content-Type': 'application/json',  
            // 可以根据需要添加授权头  
            'Authorization': `Bearer ${token}`  
        }  
    });  
};  
